import random

import pygame

WAIT, MOVE = xrange(2)
IGNORE, DIE, ATTACK = xrange(3)

class Node(object):
	movement = WAIT
	action = IGNORE
	
	def __init__(self, position):
		self.position = position
		self.children = set()
	
	def link(self, node):
		self.children.add(node)
		
	def next_node(self):
		return random.choice(tuple(self.children))
	
	def draw_links(self, surface):
		for child in self.children:
			pygame.draw.line(surface, (192, 192, 192), self.position, child.position)

class Move(Node):
	movement = MOVE
	action = IGNORE
	
	@classmethod
	def path(cls, *points):
		nodes = [cls(point) for point in points]
		
		for index, node in enumerate(nodes[:-1]):
			node.link(nodes[index + 1])
			
		return nodes

class Attack(Node):
	movement = WAIT
	action = ATTACK
	
	@classmethod
	def path(cls, point, target):		
		return [cls(point, target)]
	
	def __init__(self, position, target):
		super(Attack, self).__init__(position)
		
		self.target = target
		
class End(Node):
	movement = WAIT
	action = DIE
	
	@classmethod
	def path(cls, *points):
		nodes = [cls(point) for point in points]
		
		for index, node in enumerate(nodes[:-1]):
			node.link(nodes[index + 1])
			
		return nodes
